package com.erp.gather.controller;

import cn.hutool.core.bean.BeanUtil;
import com.erp.gather.domain.bo.ErpSellerStoreProductSkuBo;
import com.erp.gather.domain.vo.ErpSellerStoreProductSkuVo;
import com.erp.gather.service.IErpSellerStoreProductSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.utils.bean.BeanCopyUtils;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;

import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.gather.api.domain.ErpSellerStoreProductExpand;
import com.ruoyi.gather.api.domain.ErpSellerStoreProductSku;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
 *
 * @author erp
 * @date 2023-03-28
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/seller/sellerStoreProductSku")
public class ErpSellerStoreProductSkuController extends BaseController {

    private final IErpSellerStoreProductSkuService iErpSellerStoreProductSkuService;

    @GetMapping("/getSkuPrice")
    public R<Object> getSkuPrice(String country, Long productSkuId) {
        Map<String, Object> skuPrice = iErpSellerStoreProductSkuService.getSkuPrice(productSkuId, country);
        return R.ok(skuPrice);
    }

    /**
     * 查询卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpSellerStoreProductSkuVo> list(ErpSellerStoreProductSkuBo bo, PageQuery pageQuery) {
        return iErpSellerStoreProductSkuService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpSellerStoreProductSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(iErpSellerStoreProductSkuService.queryById(id));
    }
    @GetMapping("/getSkuById")
    public ErpSellerStoreProductSku getSkuById(Long id) {
        ErpSellerStoreProductSkuVo productSkuVo = iErpSellerStoreProductSkuService.queryById(id);
        return BeanUtil.toBean(productSkuVo, ErpSellerStoreProductSku.class);
    }

    /**
     * 新增卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpSellerStoreProductSkuBo bo) {
        return toAjax(iErpSellerStoreProductSkuService.insertByBo(bo));
    }

    /**
     * 修改卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @Log(title = "卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpSellerStoreProductSkuBo bo) {
        return toAjax(iErpSellerStoreProductSkuService.updateByBo(bo));
    }

    /**
     * 删除卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     *
     * @param ids 主键串
     */
    @Log(title = "卖家在线商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpSellerStoreProductSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @PostMapping("/getSellerStoreProductSkuListInfo")
    public R<Object> getSellerStoreProductSkuListInfo(@RequestBody ErpSellerStoreProductSku sellerStoreProductSku) {
        return iErpSellerStoreProductSkuService.getSellerStoreProductSkuListInfo(sellerStoreProductSku);
    }


    @PostMapping("/deletErpSellerStoreProductSkuList")
    public R<Object> deletErpSellerStoreProductSkuList(@RequestBody List<ErpSellerStoreProductSku> sellerStoreProductSku) {
        return iErpSellerStoreProductSkuService.deletErpSellerStoreProductSkuList(sellerStoreProductSku);
    }

    @GetMapping("/getSellerStoreSkuAttr/{id}")
    R<Object> getSellerStoreSkuAttr(@PathVariable("id") Long id) {
        return iErpSellerStoreProductSkuService.getSellerStoreSkuAttr(id);
    }


}
